/* GUI CONVERTED from rcrsupb1.i (converter v1.76) Thu Apr 11 05:26:13 2002 */
/* rcrsupb1.i - RELEASE MANAGEMENT CUSTOMER SCHEDULES                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.3.1.2 $                                                       */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96        BY: TSI *K005*             */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98        BY: *K1Q4* Alfred Tan      */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00        BY: *N0KP* Mark Brown      */
/* $Revision: 1.3.1.2 $   BY: Jean Miller        DATE: 04/09/02  ECO: *P058*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* REQUIRED SHIP SCHEDULE AUTHORIZATION NUMBERS */
for each work_rqm exclusive-lock:
   delete work_rqm.
end.

rqmcnt = 0.

for each rqm_det
   where rqm_type      = schd_type
   and rqm_nbr       = schd_nbr
   and rqm_line      = schd_line
   and rqm_rlse_id   = schd_rlse_id
   and rqm_date      = schd_date
   and rqm_time      = schd_time
   and rqm_interval  = schd_interval
   and rqm_reference = schd_reference
   and rqm_cat       = "AUTHNBR"
no-lock:

   create work_rqm.
   assign
      work_rqm_value = rqm_det.rqm_value
      rqmcnt = rqmcnt + 1.
end.

if rqmcnt > 0 then do:

   auth_nbrs = rqmcnt / resch_ct. /* # AUTH'S PER REQ. */

   /********************************************************/
   /* WHEN THERE ARE MORE AUTHNBRS THAN REQUIREMENTS, AND  */
   /* THE NUMBER OF AUTHNBRS CANNOT BE DIVIDED EVENLY      */
   /* AMONG THE REQUIREMENTS, DO NOT CONTINUE.             */
   /********************************************************/
   if auth_nbrs > 1
      and rqmcnt modulo resch_ct > 0
   then do:
      msgtext = string(schd_date) + "/" +
                schd_time + "/" +
                string(resch_ct) + "/" +
                string(rqmcnt).
      /* Cannot evenly distribute */
      {pxmsg.i &MSGNUM=1520 &ERRORLEVEL=4 &MSGARG1=msgtext}
      undo, return.
   end.

   /********************************************************/
   /* WHEN THERE ARE MORE AUTHNBRS THAN REQUIREMENTS,      */
   /* EVENLY DISTRIBUTE THE REQUIREMTENT QUANTITY AMONG    */
   /* THE AUTHNBRS.                                        */
   /********************************************************/
   else if auth_nbrs > 1
   then do:
      s = 0.
      do n = 1 to resch_ct:
         assign
            new_qty = truncate(resch_qty[n] / auth_nbrs, 0)
            mod_qty = resch_qty[n] modulo auth_nbrs.

         do x = 1 to auth_nbrs:
            assign
               s = s + 1
               auth_qty[s] = if x = auth_nbrs
               then new_qty + mod_qty else new_qty
               auth_date[s] = resch_dt[n].
         end.
      end.

      do x = 1 to s:
         assign
            resch_qty[x] = auth_qty[x]
            resch_dt[x] = auth_date[x].
      end.

      resch_ct = s.

   end. /* if auth_nbrs > 1 */

   /********************************************************/
   /* ARE THERE MORE REQUIREMENTS THAN AUTHNBRS?           */
   /********************************************************/
   else if auth_nbrs < 1
      and rqmcnt = 1
   then do:

      rqmvalue = work_rqm_value.

      if so_auth_days > 0 then do:
         msgtext = string(schd_date) + "/" +
            schd_time + "/" +
            rqmvalue.
         /* Cannot Distribute ONE*/
         {pxmsg.i &MSGNUM=1521 &ERRORLEVEL=4 &MSGARG1=msgtext}
         undo, return.
      end.

      /* DUPLICATE THE AUTHNBR FOR EACH SHIPMENT*/
      else
      do x = 1 to resch_ct - 1:
         create work_rqm.
         assign
            work_rqm_value = rqmvalue.
      end.

   end. /* if auth_nbrs < 1 */

   /********************************************************/
   /* WHEN THERE ARE MORE REQUIREMENTS, THAN AUTHNBRS AND  */
   /* THE NUMBER OF AUTHNBRS CANNOT BE DIVIDED EVENLY      */
   /* AMONG THE REQUIREMENTS, DO NOT CONTINUE.             */
   /********************************************************/
   if auth_nbrs < 1 then do:
      msgtext = string(schd_date) + "/" +
         schd_time + "/" +
         string(resch_ct) + "/" +
         string(rqmcnt).
      /* Cannot evenly distribute */
      {pxmsg.i &MSGNUM=1520 &ERRORLEVEL=4 &MSGARG1=msgtext}
      undo, return.
   end. /* if auth_nbrs < 1 */

end. /* if rqmcnt > 0 */
